package com.netease.commenta.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.netease.commenta.model.Commodity;
import com.netease.commenta.R;

import java.util.List;

/**
 * Created by Ben on 2017/2/26.
 */

public class CommodityAdapter extends ArrayAdapter<Commodity> {
    private Context context;
    private int resource;

    public CommodityAdapter(Context context, int resource, List<Commodity> list) {
        super(context, resource, list);
        this.context = context;
        this.resource = resource;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Commodity item = this.getItem(position);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(resource, null);
        ((TextView)view.findViewById(R.id.commodityName)).setText(item.getName());
        return view;
    }
}
